package com.yanqu.road.server.cmd.rank;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.logic.helper.UnionActivityGroupHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.pb.rank.YRankProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CROSS_ACTIVITY_USER_RANK, desc = "获取跨服活动个人排名")
public class CrossActivityUserRankCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        RankProto.CrossActivityUserRankReqMsg reqMsg = RankProto.CrossActivityUserRankReqMsg.parseFrom(packet.getBytes());

        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(reqMsg.getActivityId());
        if (activityInfo != null) {
            // 商会分组活动走这边
            if (UnionActivityGroupHelper.isGroupActivityType(activityInfo.getType())) {
                YRankProto.YRankReqMsg.Builder builder = YRankProto.YRankReqMsg.newBuilder();
                builder.setActivityId(activityInfo.getActivityId());
                builder.setGroupId(GameUnionActivityGroupMgr.getGroupId(activityInfo.getActivityId(), player.getUserId()));
                builder.setIdKey(String.valueOf(reqMsg.getConditionType()));
                player.sendUnionActivityGroupPacket(CrossProtocol.C2_CROSS_YRANK_GET_USER_RANK_NUM, builder, activityInfo.getActivityId());
                return;
            }
        }

        player.sendPacket(CrossProtocol.C2_CROSS_ACTIVITY_USER_RANK, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
